package org.airline.service;

import java.util.List;

import javax.annotation.Resource;

import org.airline.dao.IMessageDao;
import org.airline.entity.Message;
import org.airline.entity.PageBean;
import org.springframework.stereotype.Component;

@Component("MessageService")
public class MessageService implements IMessageDao {
	
	private IMessageDao iMessageDao;

	// 删除留言对象
	@Override
	public void deleteMessage(int id) throws Exception {
		iMessageDao.deleteMessage(id);
	}

	// 查询所有留言对象
	@Override
	public List<Message> getAllMessage() throws Exception {
		return iMessageDao.getAllMessage();
	}

	// 根据ID查询留言对象
	@Override
	public Message getMessageById(int id) throws Exception {
		return iMessageDao.getMessageById(id);
	}

	// 根据关键字全文搜索留言对象
	@Override
	public List<Message> getMessageByKeyWord(String keyWord) throws Exception {
		return iMessageDao.getMessageByKeyWord(keyWord);
	}

	// 根据标题查询留言对象
	@Override
	public List<Message> getMessageByTitle(String title) throws Exception {
		return iMessageDao.getMessageByTitle(title);
	}

	// 根据用户ID查询所有留言对象
	@Override
	public List<Message> getMessageByUserId(int id) throws Exception {
		return iMessageDao.getMessageByUserId(id);
	}

	// 持久化留言对象
	@Override
	public void saveMessage(Message message) throws Exception {
		iMessageDao.saveMessage(message);
	}

	// 修改留言对象信息
	@Override
	public void updateMessage(Message message) throws Exception {
		iMessageDao.updateMessage(message);
	}
	
	// 分页查询
	@Override
	public PageBean queryForPage(int pageSize, int page) throws Exception {
		return iMessageDao.queryForPage(pageSize, page);
	}

	// 根据用户ID分页查询
	@Override
	public PageBean queryForPageByUserId(int id, int pageSize, int page)
	throws Exception {
		return iMessageDao.queryForPageByUserId(id, pageSize, page);
	}

	public IMessageDao getiMessageDao() {
		return iMessageDao;
	}

	@Resource(name = "MessageDaoImpl")
	public void setiMessageDao(IMessageDao iMessageDao) {
		this.iMessageDao = iMessageDao;
	}

	// 根据发布时间查询前5条记录
	@Override
	public List<Message> getMessageByDate() throws Exception {
		return iMessageDao.getMessageByDate();
	}

	@Override
	public PageBean queryForPageByKeyWords(String keyWord, int pageSize,
			int page) throws Exception {
		return iMessageDao.queryForPageByKeyWords(keyWord, pageSize, page);
	}


}
